const express = require('express');
const router = express.Router();
const { notificationModel } = require('../model/db');

// 获取未读通知数量
router.get('/unread/count', async (req, res) => {
  try {
    const unreadCount = await notificationModel.countDocuments({ isRead: false });
    res.send({ code: 200, count: unreadCount });
  } catch (error) {
    console.error('获取未读通知数量失败:', error);
    res.status(500).send({ code: 500, msg: '服务器内部错误' });
  }
});

// 获取未读通知
router.get('/unread', async (req, res) => {
  try {
    const unreadNotifications = await notificationModel.find({ isRead: false });
    res.send({ code: 200, data: unreadNotifications });
  } catch (error) {
    console.error('获取未读通知失败:', error);
    res.status(500).send({ code: 500, msg: '服务器内部错误' });
  }
});

module.exports = router;